package com.sbdev.controller;


import com.sbdev.dic.SexEnum;
import com.sbdev.pojo.User;
import com.sbdev.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController // REST风格网站
@RequestMapping("/user")
public class UserController {
    // 用户服务接口
    @Autowired
    private UserService userService = null;

    /**
     * 获取用户信息
     * @param id 用户编号
     * @return 用户信息
     */
    @GetMapping("/info/{id}")
    public User getUser(@PathVariable("id") Long id) {
        User user = userService.getUser(id);
        return user;
    }

    @GetMapping("/addition/{id}")
    public User insertUser(@PathVariable("id") Long id) {
        User user = new User();
        user.setSex(SexEnum.getSexEnum(id.intValue()%2));
        user.setUserName("user_name_" + id);
        user.setNote("note_" + id);
        userService.insertUser(user);
        return user;
    }

    @GetMapping("/print/{user}")
    public User print(User user) {
        return user;
    }
}
